
var threshold = {
	/**
	 * Show  list
	 */
	list : function() {
		var serverlistUrl = baseURL + "/system/threshold/list"
		$.ajax({
			type : "get",
			url : serverlistUrl,
			dataType : "html",
			success : function(html) {
				// Request successfully and fill the data.
				$("#list").empty().html(html);
			}
		});
	},
	/**
	 * remove 
	 */	
	remove : function(){
		var thresholds = [];
		//将选中数据添加到数组中
		$('input[name="id"]:checked').each(function(){
			thresholds.push($(this).val());
		});
		if(thresholds==""){
			common.showTip({
				title : localeMsg.common.warn,
				text : localeMsg.common.selectMsg
			});
		}else{
			$.ajax({
				type : "get",
				url : baseURL+"/system/threshold/remove",
				data : {
					"thresholds" : thresholds
				},
				dataType : "json",
				traditional : true,
				success : function(json){
					if(json.result && json.result == "success"){
						common.showTip({
							title : localeMsg.common.prompt,
							text : localeMsg.common.deleteSuccess,
							callback : function(){
								threshold.list();
							}
						});
					}else{
						common.showTip({
							title : localeMsg.common.warn,
							text : localeMsg.common.deletefail,
							success: false
						});
					}
				}
			});
		}
	},
	/**
	 * New target
	 */
	create : function() {
		var title = localeMsg.threshold.create;
		common.dialog({
			obj : "#editThresholdDialog",
			type : "get",
			url : baseURL + "/system/threshold/edit",
			title : title,
			width : 600,
			heigth : 300,
			confirm : function() {
				var data = $("#editThresholdForm").form('validate');
				if (data == true) {
					threshold.save();
				} else {
					common.showTip({
						title : localeMsg.common.warn,
						text : localeMsg.common.invalidData
					});
				}
			}
		});
	},
	/**
	 * Edit target
	 */
	edit : function(value) {
		// Get the first targetId from checked buttons.
		var thresholdId = value;
		// The title of edit dialog
		var title = localeMsg.threshold.create;
		var param = {};
		// If id is not empty, edit the target info; or new it.
		title = localeMsg.threshold.edit;
		param.thresholdId = thresholdId;
		common.dialog({
			obj : "#editThresholdDialog",
			type : "get",
			url : baseURL + "/system/threshold/edit",
			param : param,
			title : title,
			width : 400,
			confirm : function() {
				var data = $("#editThresholdForm").form('validate');
				if (data == true) {
					threshold.save();
				} else {
					common.showTip({
						title : localeMsg.common.warn,
						text : localeMsg.common.invalidData
					});
				}
			}
		});
	},
	
	/**
	 * Save pool
	 */
	save : function() {
		$("#editThresholdForm").ajaxSubmit({
			success : function(json) {
				// Save successfully and refresh the user list.
				if (json.result && json.result == "success") {
					common.showTip({
						title : localeMsg.common.prompt,
						text : localeMsg.common.saveSuccess,
						success : true,
						callback : function() {
							threshold.list();
						}
					});
				} else {
					common.showTip({title : localeMsg.common.warn, text : localeMsg.common.saveFailed});
				}
			}
		});
	},
	/**
	 * validate form
	 */
	validate : function() {
		// poolName 验证非空，
		/*$('#creator').validatebox({
			required : true,
			// 在页面取所有的name与传进来的value值比较
			validType : 'name'
		}); */
		$('#val').validatebox({
			required : true,
			// 在页面取所有的name与传进来的value值比较
			validType : 'value'
		});
	},
};